package com.szc.fs.util;

import com.alibaba.fastjson.JSON;
import com.szc.fs.config.JQRConstants;
import com.szc.fs.pojo.NewsInfo;
import com.szc.fs.pojo.message.MessageArticle;
import com.szc.fs.pojo.message.MessageContent;
import com.szc.fs.pojo.message.MessageContext;
import com.szc.fs.pojo.message.MessageData;

import java.util.ArrayList;
import java.util.List;

/**
 * @title: MessageUtil
 * @Author Liuyang Tian
 * @Date: 2023/2/16 15:43
 * @Version 1.0
 */
public class MessageUtil {

    public static MessageContent getMessageContent(List<NewsInfo> articles ){
        MessageContext cx = new MessageContext();
        cx.setMark(PropertiesUtil.getConfig(JQRConstants.JQR_TEMPLATE_MARK_PREFIX)+"<a href='"+ PropertiesUtil.getConfig(JQRConstants.JQR_TEMPLATE_MARK_URL) +"'>"+
                PropertiesUtil.getConfig(JQRConstants.JQR_TEMPLATE_MARK_MESSAGE)
                +"</a>");
        cx.setTitle(PropertiesUtil.getConfig(JQRConstants.JQR_TEMPLATE_TITLE));
        ArrayList<MessageArticle> messageArticles = new ArrayList<>();
        for (NewsInfo article : articles) {
            String title = article.getTitle();
            String url = article.getUrl();
            messageArticles.add(new MessageArticle("<strong><a href='"+url+"'>"+title+"</a></strong>"));
        }
        cx.setArticle_set(messageArticles);
        System.out.println(JSON.toJSONString(cx));
       return new MessageContent("template",new MessageData(PropertiesUtil.getConfig(JQRConstants.JQR_TEMPLATE_ID),cx));

    }
}
